package com.zx.task.manager.controller;

import com.zx.core.wrapper.ListWrapper;
import com.zx.core.wrapper.ResponseWrapper;
import com.zx.log.annotation.OperateLog;
import com.zx.task.manager.param.TaskTypesParam;
import com.zx.task.manager.service.ITaskTypesService;
import com.zx.task.manager.vo.TaskTypesVO;
import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.annotation.ParameterValidations;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Create;
import com.zx.validation.groups.Update;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * description: 任务类型控制器 <br>
 * create: 2025-10-13 20:15
 * </p>
 *
 * @author zhou  xun
 */
@RestController
@RequestMapping("/taskTypes")
@RequiredArgsConstructor
public class TaskTypesController {

    private final ITaskTypesService iTaskTypesService;

    /**
     * 查询任务类型列表
     *
     * @param taskTypesParam 查询参数
     * @return 任务类型列表
     */
    @PreAuthorize("hasAuthority('task:type:list')")
    @GetMapping("/list")
    public ListWrapper<TaskTypesVO> list(TaskTypesParam taskTypesParam) {
        return iTaskTypesService.getTaskTypesVOList(taskTypesParam);
    }

    /**
     * 新增任务类型
     *
     * @param taskTypesParam 任务类型参数
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "新增任务类型")
    @PreAuthorize("hasAuthority('task:type:add')")
    @PostMapping("/addTaskType")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "任务类型参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Create.class})
    )
    public ResponseWrapper addTaskType(@RequestBody TaskTypesParam taskTypesParam) {
        return iTaskTypesService.addTaskType(taskTypesParam);
    }

    /**
     * 编辑任务类型
     *
     * @param taskTypesParam 任务类型参数
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "编辑任务类型")
    @PreAuthorize("hasAuthority('task:type:edit')")
    @PutMapping("/editTaskType")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "任务类型参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Update.class})
    )
    public ResponseWrapper editTaskType(@RequestBody TaskTypesParam taskTypesParam) {
        return iTaskTypesService.editTaskType(taskTypesParam);
    }

    /**
     * 删除任务类型
     *
     * @param taskTypeId 任务类型Id
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "删除任务类型")
    @PreAuthorize("hasAuthority('task:type:remove')")
    @DeleteMapping("/deleteTaskType/{taskTypeId}")
    @ParameterValidations({
            @ParameterValidation(index = 0, desc = "任务类型Id", rules = {ValidateRulesEnum.NOT_NULL})
    })
    public ResponseWrapper deleteTaskType(@PathVariable("taskTypeId") String taskTypeId) {
        return iTaskTypesService.deleteTaskType(taskTypeId);
    }

}